package com.gexiaobao.pigeon.ui.adapter

import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.PigeonFosterBean

/**
 * created by : hxw
 * @date : 20221129
 * Describe :
 */
class FosterPigeonAdapter(data: ArrayList<PigeonFosterBean.ListData>) :
    BaseQuickAdapter<PigeonFosterBean.ListData, BaseViewHolder>(R.layout.item_shed_pigeon_list, data) {

    override fun convert(holder: BaseViewHolder, item: PigeonFosterBean.ListData) {
        holder.setText(R.id.tv_item_pigeon_nickname, item.memberName.ifEmpty { context.getString(R.string.No_nickname_yet) })
        holder.setText(R.id.tv_item_pigeon_zh_code, item.ringId)
        holder.setText(R.id.tv_item_pigeon_sex, getPigeonSex(item.sex))
        holder.setText(R.id.tv_item_pigeon_eye_color, getEyePattern(item.eyePattern))
        holder.setVisible(R.id.tv_item_pigeon_state, false)//1、训放  2、比赛  3、正常（3种状态）
        holder.setVisible(R.id.tv_item_pigeon_delete, false)

        holder.setText(R.id.tv_item_pigeon_color, item.featherColor)

        val tvItemPairStatus = holder.getView<AppCompatTextView>(R.id.tvItemPairStatus)

        if (item.userId == 0) {
            tvItemPairStatus.text = context.getString(R.string.Unpaired)
            tvItemPairStatus.setTextColor(ContextCompat.getColor(context, R.color.color_fe4542))
        } else {
            tvItemPairStatus.text = context.getString(R.string.Already_paired)
            tvItemPairStatus.setTextColor(ContextCompat.getColor(context, R.color.colorAccent))
        }

        when (item.sex) {
            2 -> holder.setBackgroundResource(R.id.tv_item_pigeon_sex, R.drawable.round_pigeon_sex_ci_color_bg15)
            3 -> holder.setBackgroundResource(R.id.tv_item_pigeon_sex, R.drawable.round_pigeon_sex_xiong_color_bg15)
            else -> holder.setBackgroundResource(R.id.tv_item_pigeon_sex, R.drawable.round_pigeon_unknown_bg15)
        }
        when (item.eyePattern) {
            2, 3, 4 -> holder.setBackgroundResource(R.id.tv_item_pigeon_eye_color, R.drawable.round_pigeon_eye_color_bg15)
            else -> holder.setBackgroundResource(R.id.tv_item_pigeon_eye_color, R.drawable.round_pigeon_unknown_bg15)
        }
    }

    private fun getEyePattern(eye: Int): String {
        return when (eye) {
            2 -> context.getString(R.string.pigeon_yellow)//"黄"
            3 -> context.getString(R.string.pigeon_sha)//"砂"
            4 -> context.getString(R.string.pigeon_bull)//"牛"
            else -> context.getString(R.string.unkown)//"未知"
        }
    }

    private fun getPigeonSex(sex: Int): String {
        return when (sex) {
            2 -> context.getString(R.string.hint_female)//"雌"
            3 -> context.getString(R.string.hint_male)//"雄"
            else -> context.getString(R.string.unkown)//"未知"
        }
    }
}